//
//  detailViewController.swift
//  TableView的使用
//
//  Created by ios on 16/8/9.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit

class detailViewController: UIViewController {

    var callBack: (()->())?
    
    @IBOutlet weak var nameTextField: UITextField!
    
    
   @IBOutlet weak var ageTextField: UITextField!
    
    var person: Person?
    override func viewDidLoad() {
        super.viewDidLoad()
        nameTextField.text = person?.name
        ageTextField.text = "\(person?.age ?? 0)"

    }
    
//  保存按钮点击事件
 @IBAction func saveButton(sender: AnyObject) {
    //获取文本框里面的内容
    let name = nameTextField.text
    let age = ageTextField.text
    
    //通过传过来的person对象来修改信息
     person?.name = name
     person?.age = Int(age!) ?? 0
    
     callBack?()
    
     navigationController?.popViewControllerAnimated(true)
    
    }
    @IBAction func textChange(sender: AnyObject) {
        navigationItem.rightBarButtonItem?.enabled = nameTextField.hasText() && ageTextField.hasText()
    }
}
